<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;

use App\Agent_login_log;
use App\Agent;
use App\Agent_account_log;
use App\Agent_user_log;
use App\Agent_level;
//use App\User;
use App\Notice;
use App\Product;
use App\Product_type;
use App\Common\ErrorDefine;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class NoticeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */

    public function __construct()
    {
        //
    }

    /**
     * @param Request $request
     * 插入公告
     */
    public function InsetNotice(Request $request)
    {
        $where = [];
        if(empty($request->all()))
        {
            self::ShowError(ErrorDefine::EMPTY_POST_DATA);
            return;
        }

        //  名称
        if(!$request->has('content') && !empty($request->input('content')))
        {
            self::ShowError(ErrorDefine::INVALID_CONTENT);
            return;
        }
        $where['content'] = $request->input('content');


        $where['terrace_id'] = $request->input('terrace_id');

        $id = Notice::insertGetId($where);

        return self::ShowMessage();

    }


    public function getNoticeList(Request $request)
    {

        $where = [];

        if(empty($request->all()))
        {
            self::ShowError(ErrorDefine::EMPTY_POST_DATA);
            return;
        }

        $terrace_id = $request->input('terrace_id');


        $notices = Notice::where('terrace_id',$terrace_id)->orderBy('created_at','desc')->first()->toArray();


        return $notices;

    }



}